﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Xml;

namespace RetrieveEntityDetails.Utility
{
    class XMLParser
    {
        public string NodeName;
        public string NodePath = "/config";
        public string NodeAttribute;        

        XmlDocument AppCofig;

        public XMLParser()
        {
            AppCofig = new XmlDocument();
            AppCofig.Load(AppDomain.CurrentDomain.BaseDirectory.ToString()+"CustomConfig.xml");
        }

        public string RetrieveAttributeValue()
        {
            XmlNode Node = AppCofig.SelectSingleNode(NodePath+"/"+NodeName);
            string ReturnValue = string.Empty;
            foreach (XmlAttribute AttributeItem in Node.Attributes)
            {
                if (AttributeItem.Name == NodeAttribute)
                    return AttributeItem.Value;
            }
            return ReturnValue;
        }

        public string RetrieveKeyValue(string Key)
        {
            XmlNodeList Nodes = AppCofig.SelectNodes(NodePath + "/setting");
            string ReturnValue = string.Empty;
            foreach (XmlNode Node in Nodes)
            {                
                  if (Node.Attributes["key"].Value == Key )
                      return Node.Attributes["value"].Value;
                
            }
            return ReturnValue;
        }
    }
}
